Coverage Report

Created: 2021-08-28 18:14

D:\git\skunkworks\herald-for-cpp\herald\src\datatype\time_interval.cpp
Line
Count
Source (jump to first uncovered line)
1
//  Copyright 2020-2021 Herald Project Contributors
2
//  SPDX-License-Identifier: Apache-2.0
3
//
4
5
#include "herald/datatype/time_interval.h"
6
7
namespace herald {
8
namespace datatype {
9
10
// class TimeInterval::Impl {
11
// public:
12
//   Impl();
13
//   Impl(long secondsSinceUnixEpoch);
14
//   ~Impl() = default;
15
16
//   long seconds;
17
// };
18
19
// TimeInterval::Impl::Impl() : seconds(0) { }
20
21
// TimeInterval::Impl::Impl(long secondsSinceUnixEpoch) : seconds(secondsSinceUnixEpoch) { }
22
23
24
25
26
27
TimeInterval
28
122
TimeInterval::minutes(long minutes) {
29
122
  return TimeInterval(60 * minutes);
30
122
}
31
32
TimeInterval
33
7
TimeInterval::seconds(long seconds) {
34
7
  return TimeInterval(seconds);
35
7
}
36
37
TimeInterval
38
43
TimeInterval::never() {
39
43
  return TimeInterval(LONG_MAX);
40
43
}
41
42
TimeInterval
43
18
TimeInterval::zero() {
44
18
  return TimeInterval(0);
45
18
}
46
47
48
TimeInterval::TimeInterval(long seconds)
49
 : secs(seconds)
50
225
{
51
225
  ;
52
225
}
53
54
TimeInterval::TimeInterval(const Date& date)
55
 : secs(date.secondsSinceUnixEpoch())
56
0
{
57
0
  ;
58
0
}
59
60
TimeInterval::TimeInterval(const Date& from, const Date& to)
61
 : secs(to.secondsSinceUnixEpoch() - from.secondsSinceUnixEpoch())
62
43
{
63
43
  ;
64
43
}
65
66
TimeInterval::TimeInterval(const TimeInterval& other)
67
  : secs(other.secs)
68
37
{
69
37
  ;
70
37
}
71
72
301
TimeInterval::~TimeInterval() {}
73
74
75
TimeInterval&
76
TimeInterval::operator=(const TimeInterval& other) noexcept
77
10
{
78
10
  secs = other.secs;
79
10
  return *this;
80
10
}
81
82
TimeInterval
83
0
TimeInterval::operator*(const TimeInterval& other) noexcept {
84
0
  return TimeInterval(secs * other.secs);
85
0
}
86
87
TimeInterval
88
0
TimeInterval::operator+(const TimeInterval& other) noexcept {
89
0
  return TimeInterval(secs + other.secs);
90
0
}
91
92
TimeInterval&
93
0
TimeInterval::operator+=(const TimeInterval& other) noexcept {
94
0
  secs += other.secs;
95
0
  return *this;
96
0
}
97
98
TimeInterval
99
0
TimeInterval::operator-(const TimeInterval& other) noexcept {
100
0
  return TimeInterval(secs - other.secs);
101
0
}
102
103
TimeInterval&
104
0
TimeInterval::operator-=(const TimeInterval& other) noexcept {
105
0
  secs -= other.secs;
106
0
  return *this;
107
0
}
108
109
TimeInterval
110
TimeInterval::operator*(double multiplier) noexcept
111
0
{
112
0
  auto output = secs * multiplier;
113
0
  return TimeInterval(static_cast<decltype(secs)>(output));
114
0
}
115
116
TimeInterval&
117
TimeInterval::operator*=(double multiplier) noexcept
118
0
{
119
0
  auto output = secs * multiplier;
120
0
  secs = static_cast<decltype(secs)>(output);
121
0
  return *this;
122
0
}
123
124
TimeInterval
125
TimeInterval::operator/(double divisor) noexcept
126
0
{
127
0
  if (0 == divisor) {
128
0
    return *this;
129
0
  }
130
0
  auto output = secs / divisor;
131
0
  return TimeInterval(static_cast<decltype(secs)>(output));
132
0
}
133
134
TimeInterval&
135
TimeInterval::operator/=(double divisor) noexcept
136
0
{
137
0
  if (0 == divisor) {
138
0
    return *this;
139
0
  }
140
0
  auto output = secs / divisor;
141
0
  secs = static_cast<decltype(secs)>(output);
142
0
  return *this;
143
0
}
144
145
0
TimeInterval::operator long() const noexcept {
146
0
  return millis();
147
0
}
148
149
  
150
bool
151
TimeInterval::operator>(const TimeInterval& other) const noexcept
152
27
{
153
27
  return secs > other.secs;
154
27
}
155
156
bool
157
TimeInterval::operator>=(const TimeInterval& other) const noexcept
158
6
{
159
6
  return secs >= other.secs;
160
6
}
161
162
bool
163
TimeInterval::operator<(const TimeInterval& other) const noexcept
164
10
{
165
10
  return secs < other.secs;
166
10
}
167
168
bool
169
TimeInterval::operator<=(const TimeInterval& other) const noexcept
170
0
{
171
0
  return secs <= other.secs;
172
0
}
173
174
bool
175
TimeInterval::operator==(const TimeInterval& other) const noexcept
176
5
{
177
5
  return secs == other.secs;
178
5
}
179
180
bool
181
TimeInterval::operator!=(const TimeInterval& other) const noexcept
182
14
{
183
14
  return secs != other.secs;
184
14
}
185
186
long
187
6
TimeInterval::millis() const noexcept {
188
6
  if (LONG_MAX == secs) {
189
1
    return LONG_MAX;
190
1
  }
191
5
  return secs * 1000;
192
5
}
193
194
long
195
33
TimeInterval::seconds() const noexcept {
196
33
  return secs;
197
33
}
198
199
2
TimeInterval::operator std::string() const noexcept {
200
2
  if (secs == LONG_MAX) {
201
1
    return "never";
202
1
  }
203
1
  return std::to_string(secs);
204
1
}
205
206
207
} // end namespace
208
} // end namespace